﻿//======================================================================
//
//        Copyright (C) 苏州逸仙软件    
//        All rights reserved
//
//        filename : D_T_ExpertBlog_Exp.cs
//        description :
//
//        created by 周济 at 2010/12/26 15:58:17
//        mail:13912699233@139.com
//
//======================================================================


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace huaguwang
{
    /// <summary>
    /// 专家博客扩展
    /// </summary>
    public class D_T_ExpertBlog_Exp : D_T_ExpertBlog
    {

        //        SELECT     a.Title AS Expr16, b.id AS Expr1, b.Title AS Expr2, a.InteriorKey, b.Topis, b.RemSign
        //FROM         dbo.T_ExperInfot AS a INNER JOIN
        //                      dbo.T_ExpertBlog AS b ON a.id = b.ExpertID
        //WHERE     (b.Flag = 1)

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="FID">专家id,如果小于等于0表示,查询所有</param>
        /// <param name="Name">专家名称</param>
        /// <param name="BlogName">博客标题</param>
        /// <returns></returns>
        public int Find(int FID, string Name, string BlogName)
        {
            var strWhere = "";
            if(FID > 0)
            {
                strWhere = " a.id=" +
                    FID +
                    "  and b.flag=1 and a.InteriorKey like '%'+@Name+'%' and b.title like '%'+@BlogName+'%'";
            }
            else
            {
                strWhere = " b.flag=1 and a.InteriorKey like '%'+@Name+'%' and b.title like '%'+@BlogName+'%'";
            }

            var strSql = ExpandMSSQL.GetPageSQL(
                    "dbo.T_ExperInfot AS a INNER JOIN dbo.T_ExpertBlog AS b ON a.id = b.ExpertID ",
                    strWhere
                );

            var ds = MSSQLHelper.SQLConType.C1.Exp_GetSingle(
                        strSql,
                        new SqlParameter("@Name", SqlDbType.NVarChar) { Value = Name },
                        new SqlParameter("@BlogName", SqlDbType.NVarChar) { Value = BlogName }
                        );
            return ds.Exp_IntTryParse();
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="begin"></param>
        /// <param name="page"></param>
        /// <param name="FID">专家id,如果小于等于0表示,查询所有</param>
        /// <param name="Name">专家名称</param>
        /// <param name="BlogName">博客标题</param>
        /// <returns></returns>
        public DataTable Find(int begin, int page, int FID, string Name, string BlogName)
        {

            
            var strWhere = "";
            if(FID > 0)
            {
                strWhere = " a.id=" +
                    FID +
                    "  and b.flag=1 and a.InteriorKey like '%'+@Name+'%' and b.title like '%'+@BlogName+'%'";
            }
            else
            {
                strWhere = " b.flag=1 and a.InteriorKey like '%'+@Name+'%' and b.title like '%'+@BlogName+'%'";
            }

            var strSql = ExpandMSSQL.GetPageSQL(
                    begin,
                    page,
                    "a.Title AS Title, b.id AS id, b.Title AS blgTitle, a.InteriorKey,Topis=case when b.Topis=1 then '是' else '否' end , " +
                        "RemSign=case when  b.RemSign=1 then '是' else '否' end ,b.UploadDate,userName=dbo.f_GetUserName(a.UserID)",
                    "dbo.T_ExperInfot AS a INNER JOIN dbo.T_ExpertBlog AS b ON a.id = b.ExpertID ",
                    " b.id ",
                    strWhere,
                    " b.id desc ");


            var ds = MSSQLHelper.SQLConType.C1.Exp_Query(
                        strSql,
                        new SqlParameter("@Name", SqlDbType.NVarChar) { Value = Name },
                        new SqlParameter("@BlogName", SqlDbType.NVarChar) { Value = BlogName }
                        );
            return ds.Tables[0];

        }


    }
}
